package com.gotop.common.utils.support;

import com.baomidou.mybatisplus.core.toolkit.support.BiIntFunction;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

/**
 * @program: cem
 * @description:
 * @author: superfish
 * @create: 2020-12-28 18:02
 **/
public class XssFilter implements Filter {
    private XssProperties xssProperties;
    private XssUrlProperties xssUrlProperties;

    public void init(FilterConfig config) {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        String path = ((HttpServletRequest) request).getServletPath();
        if (this.isSkip(path)) {
            chain.doFilter(request, response);
        } else {
            XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper((HttpServletRequest) request);
            chain.doFilter(xssRequest, response);
        }

    }

    /**
     * 增加判断固定地址不过滤
     *
     * @param path
     * @return
     */
    private boolean isSkip(String path) {
        final List<String> excludePatterns = this.xssUrlProperties.getExcludePatterns();
        return false;
    }

    public void destroy() {
    }

    public XssFilter(final XssProperties xssProperties, final XssUrlProperties xssUrlProperties) {
        this.xssProperties = xssProperties;
        this.xssUrlProperties = xssUrlProperties;
    }
}